package com.vegetable.modules.service.baseData.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.common.utils.Query;
import com.vegetable.modules.entity.baseData.ProductCostClause;
import com.vegetable.modules.mapper.baseData.ProductCostClauseMapper;
import com.vegetable.modules.service.baseData.IProductCostClauseService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品代办包装费用标准 服务实现类
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-05
 */
@Slf4j
@Service
@AllArgsConstructor
public class ProductCostClauseServiceImpl extends ServiceImpl<ProductCostClauseMapper, ProductCostClause> implements IProductCostClauseService {

    /**
     * 商品代办包装费用标准
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String producerId = (String)params.get("producerId");
        IPage<ProductCostClause> page = this.page(
                new Query<ProductCostClause>().getPage(params),
                new QueryWrapper<ProductCostClause>()
                        .eq(StringUtils.isNotBlank(producerId),"producer_id", producerId)
        );

        return new PageUtils(page);
    }

    @Override
    public List<ProductCostClause> queryByProducerId(Long productId) {
        QueryWrapper<ProductCostClause> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("producer_id", productId);
        return baseMapper.selectList(queryWrapper);
    }
}
